/*
 * Copyright (C) 2015-2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#ifndef PLANET_WARS_2D_RT_CORE_MODEL_SHIP_LIFE_H
#define PLANET_WARS_2D_RT_CORE_MODEL_SHIP_LIFE_H


#include "PlanetWars2dRT-core/specific/model/ship_essential.h"


EXTERN_C_BEGIN


static inline
unsigned int
ship_get_life_current_unsafe(const ship_t* a_ship)
{
  return a_ship->life_current;
}

static inline
unsigned int
ship_get_life_current(const ship_t* a_ship)
{
  return a_ship == NULL ? 0 : ship_get_life_current_unsafe(a_ship);
}

static inline
bool
ship_set_life_current(ship_t* a_ship, unsigned int value)
{
  if(a_ship == NULL && value > a_ship->life_max)
    {
      return false;
    }
  a_ship->life_current = value;
  return true;
}

static inline
unsigned int
ship_get_life_max(const ship_t* a_ship)
{
  return a_ship == NULL ? 0 : a_ship->life_max;
}


void
ship_notify_life_changed(ship_t* a_ship);

void
ship_notify_destroyed(ship_t* a_ship);


void
ship_reduce_life_no_notify(ship_t* a_ship, unsigned int life);

void
ship_reduce_life(ship_t* a_ship, unsigned int life);

static inline
void
ship_destroy_no_notify(ship_t* a_ship)
{
  a_ship->life_current = 0;
}

void
ship_destroy(ship_t* a_ship);

static inline
bool
ship_is_destroyed(const ship_t* a_ship)
{
  return a_ship->life_current == 0;
}


EXTERN_C_END


#endif
